package com.shiliao.app.activity.index.presenter;

import android.text.TextUtils;

import com.shiliao.app.activity.index.entity.AddRemindEntity;
import com.shiliao.app.activity.index.service.IAddRemindService;
import com.shiliao.app.activity.index.service.impl.AddRemindImpl;
import com.shiliao.app.activity.index.view.AddRemindView;
import com.shiliao.app.utils.YMServerUtil;
import com.yimei.framework.mvp.presenter.IBasePresenter;
import com.yimei.framework.network.ICallBack;
import com.yimei.framework.util.LogUtil;
import com.yimei.framework.util.ParseHelper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by yinzhiqiang on 2017/10/9.
 */

public class AddRemindPresenter extends IBasePresenter<IAddRemindService> {
    private AddRemindView addRemindView;
    private IAddRemindService addRemindService;

    public AddRemindPresenter(AddRemindView addRemindView) {
        this.addRemindView = addRemindView;
        addRemindService = new AddRemindImpl();
        setService(addRemindService);
    }

    public void requestRemind(String article_id) {
        Map map = new HashMap();
        if (!TextUtils.isEmpty(article_id)) {
            map.put("article_id", article_id);
        }
        addRemindService.requestRemind(YMServerUtil.ACTION_REMIND, map, new ICallBack() {
            @Override
            public void onSuccess(int statusCode, Object result) {
                LogUtil.e("yzq", result.toString());
                List<AddRemindEntity> list = ParseHelper.getModelList(result.toString(), "reminder_array", AddRemindEntity.class);
                addRemindView.setAdapter(list);
            }

            @Override
            public void onFail(int statusCode, Object result) {

            }
        });
    }

    public void requestAddRemind(String reminderId, String userId) {
        Map map = new HashMap();
        if (!TextUtils.isEmpty(reminderId)) {
            map.put("reminder_id", reminderId);
        }
        if (!TextUtils.isEmpty(userId)) {
            map.put("user_id", userId);
        }
        addRemindService.requestAddRemind(YMServerUtil.ACTION_ADD_REMIND, map, new ICallBack() {
            @Override
            public void onSuccess(int statusCode, Object result) {
                LogUtil.e("yzq", result.toString());
                addRemindView.showToast();
                addRemindView.hideLoadingView();
            }

            @Override
            public void onFail(int statusCode, Object result) {

            }
        });
    }
}
